/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.portalcenter.domain.das;

import cn.hallele.infrastructure.util.ObjectUtil;
import cn.hallele.ms.infrastructure.core.convertor.das.ModelDas;
import cn.hallele.ms.portalcenter.domain.domain.RoleDomain;
import cn.hallele.ms.portalcenter.model.cache.RoleCache;
import cn.hallele.ms.portalcenter.model.entity.RoleEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * hallele_ms_portalcenter
 *
 * @author anle5
 * @since 2024/10/6 13:51
 */
@Slf4j
@Service
public class RoleDEDas extends ModelDas<RoleCache, RoleDomain, RoleEntity> {
    protected RoleDEDas(RoleCache option) {
        super(option);
    }

    /**
     * 通过id查询角色
     *
     * @param ids id集合
     * @return 角色集合结果
     */
    public List<RoleDomain> findByIdIn(Collection<Integer> ids) {
        return revertList(this.option.findByIdIn(ids));
    }

    /**
     * 通过roleCode查询role
     *
     * @param roleCodes roleCode集合
     * @return roles
     */
    public List<RoleDomain> findByCodeIn(Collection<String> roleCodes) {
        return revertList(this.option.findByCodeIn(roleCodes));
    }

    /**
     * 将T转成E
     *
     * @param roleDomain 被转换者
     * @return S 转换后者
     */
    @Override
    protected RoleEntity convert(RoleDomain roleDomain) {
        return ObjectUtil.map(roleDomain, u -> RoleEntity.builder()
                .id(u.getId())
                .name(u.getName())
                .code(u.getCode())
                .sort(u.getSort())
                .status(u.getStatus())
                .dataScope(u.getDataScope())
                .createTime(u.getCreateTime())
                .updateTime(u.getUpdateTime())
                .build());
    }

    /**
     * 将E回转陈T
     *
     * @param roleEntity 被回转换者
     * @return S 回转换后者
     */
    @Override
    protected RoleDomain revert(RoleEntity roleEntity) {
        return ObjectUtil.map(roleEntity, u -> RoleDomain.builder()
                .id(u.getId())
                .name(u.getName())
                .code(u.getCode())
                .sort(u.getSort())
                .status(u.getStatus())
                .dataScope(u.getDataScope())
                .createTime(u.getCreateTime())
                .updateTime(u.getUpdateTime())
                .build());
    }
}
